/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nsip.model;

/**
 *
 * @author nico.rehwaldt
 */
public class ProductInfo extends ProductPartInfo {
    
    private final int requiredAssemblyCycles;
    private final ProductPartInfo[] components;
    private Integer[] componentIDs = null;
    
    private int partsPrice = -1;
    
    public ProductInfo(int id, int basePrice, String name, int requiredAssemblyCycles, ProductPartInfo[] components) {
        super(id, basePrice, name, new String[0]);

        this.components = components;
        this.requiredAssemblyCycles = requiredAssemblyCycles;
    }

    /**
     * @return the requiredAssemblyCycles
     */
    public int getRequiredAssemblyCycles() {
        return requiredAssemblyCycles;
    }

    /**
     * @return the components
     */
    public ProductPartInfo[] getComponents() {
        return components;
    }

    /**
     * Return component ids
     * @return
     */
    public Integer[] getComponentIDs() {
        if (componentIDs == null) {
            componentIDs = new Integer[components.length];
            for (int i = 0; i < components.length; i++) {
                componentIDs[i] = components[i].getId();
            }
        }

        return componentIDs;
    }

    public int getPartsPrice() {
        if (partsPrice == -1) {
            partsPrice = 0;
            
            for (ProductPartInfo part: components) {
                partsPrice += part.getBasePrice();
            }
        }

        return partsPrice;
    }
}
